Expand description
A screenshots page from a VisualCI public gallery manifest, rendered in Rust
as the gallery contract’s markup: byte for byte what the visualci-gallery JS library renders, so its script
hydrates it (tabs, light and dark, desktop and phone and any dimension a site adds, the full-size view).
use visualci_gallery::{Gallery, Options};
// The manifest a build step wrote (a copy of https://app.visualci.com/g/<org>/<project>.json).
let manifest = std::fs::read_to_string("screenshots.json").expect("the build writes it");
let gallery = Gallery::from_json(&manifest, &Options::default().title(None))?;
let html = gallery.to_string();There is no fallback: rendering fails when the manifest has nothing to show or the options are invalid, and
[fetch] (feature fetch) fails when the manifest can’t be read. Read it when the site builds, fail the build if
it can’t be, and render from that copy.
With the askama feature, Gallery is safe HTML to Askama: a template writes {{ gallery }}.
Structs§
- Dimension
- A way a screen’s shots differ (contract/SPEC.md, “Dimensions”):
themeandsizeare built in, a site adds others. - Dimension
Value - Gallery
- A rendered gallery. Displays as its HTML; with the
askamafeature, Askama doesn’t escape it. - Group
- Model
- The manifest as the gallery shows it, with the keys of the contract fixtures’ model.json.
- Options
- The options a site can set (contract/SPEC.md, “Input”), as JSON-shaped values so every renderer takes the same
ones. Build them with
Options::defaultand the setters, orOptions::from_json. - Preload
Caps - The preloader’s limits:
foldabove-the-fold thumbnails always load; past them at mostcountimages andbytesbytes;parallelrequests at once. - Screen
- Screenshot
Options - What
screenshotandscreenshot_markdownshow, as JSON-shaped values like the gallery’sOptions. Build them withScreenshotOptions::newand the setters, orScreenshotOptions::from_json. - SeeAll
- Shot
- How a manifest name pairs (contract/SPEC.md, “A shot’s name”).
- Text
- The gallery’s own words (contract/SPEC.md, “Text”), every one filled in.
{title}inopenis the screen’s title;{link}increditis the link to VisualCI.labelis the default title, and the gallery’s name when its title is null.andjoins the values in an image’s alt text. - Thumb
- Variant
- Version
- A version the manifest lists.
- Versions
- The Version switch (contract/SPEC.md, “The model”): the listed versions, the one shown and Latest’s manifest.
Enums§
- Error
- Why a gallery can’t be shown.
- Missing
- What a card does with no shot for the chosen value (contract/SPEC.md, “Dimensions”):
Error, every screen needs every value;Hide, the card isn’t shown;First, it shows its own first value. - Preload
- Predictive preloading other than the default (the model’s
preload:"off", or the caps, every one filled in). - Shape
- The shape of most of a size value’s images.
Constants§
- NEW_
DAYS - The New badge’s default window, in days.
- SEARCH_
FROM - The search box’s default threshold: shown once the gallery has this many screens.
- SEE_
ALL_ TEXT - TEXT_
DEFAULTS - The gallery’s own words by key, with their defaults (contract/SPEC.md, “Text”), in the model’s order.
Functions§
- build_
model - The manifest as the gallery shows it (contract/SPEC.md). Fails when it or the options are invalid, or nothing in it can be shown.
- default_
dimensions - The built-in dimensions: the theme (light, dark) and the size (desktop, phone below 768).
- escape
- & < > “ ’ as entities: the only escaping the contract allows, so every language’s output is the same.
- humanize
["billing", "free"]→ “Billing, free”.- manifest_
url - The manifest to read for
url: the main one, or withreference(a version’s label or key,v2.0.0), that version’s,…/<project>@<key>.json(contract/SPEC.md, “Pinning a version”). The key is the server’s: ASCII lower case, each run of anything else one hyphen, none at either end. Fails when that key is empty orlatest, orurldoesn’t end in.json. - options_
json - The options as the Version switch carries them (the model’s
versions.options): those of the contract’s table that are set and not null (a null title too), as canonical JSON (contract/SPEC.md, “The model”). - parse_
shot - Trailing
--separated tokens that are value keys ofdimensions, a CSS width and2xare peeled off the end, and the rest is the screen’s key (contract/SPEC.md, “A shot’s name”). - render
- The gallery’s HTML for a parsed manifest.
- render_
model - The gallery’s markup: one line per block, no indentation, “\n” after each line.
- screenshot
- One screenshot as HTML: an
<img>, or a<picture>with the dark shot for readers whose setting is dark. Fails when the manifest or the options are invalid, or the screen has no shot for what’s asked. - screenshot_
markdown - One screenshot for a README: Markdown’s
, linked withlink, or the HTML<picture>when it has a dark shot. - slugify
- A group’s name as an id: ASCII lower case, runs of anything else as one hyphen.
Type Aliases§
- Values
- A dimension’s value key per dimension key (
{"theme": "dark", "size": "phone"}).